// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


  function geocodePosition(pos) {
    var geocoder = new google.maps.Geocoder();

    geocoder.geocode({
      latLng: pos
    }, function(responses) {
      if (responses && responses.length > 0) {
        updateMarkerAddress(responses[0].formatted_address);
      } else {
        updateMarkerAddress('Cannot determine address at this location.');
      }
    });
  }

  function updateMarkerPosition(latLng) {
    document.getElementById('latitud').value = latLng.lat();
    document.getElementById('longitud').value = latLng.lng();
  }
  function initialize() {

    var latlng = new google.maps.LatLng(10.46721252135467, -66.97320150000019);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById('mapa'), myOptions);
    var marker = new google.maps.Marker({
      position: latlng,
      draggable: true,
      map: map
    });

    updateMarkerPosition(latlng);
    google.maps.event.addDomListener(window, 'load', initialize);
  }

function eliminar_campos(link){
    $(link).previous("input[type=hidden]").value = "1";
    $(link).up(".fields").hide();
}

function agregar_campos(link, association,content){
   var new_id = new Date().getTime();
    var regexp = new RegExp("new_"+association,"g")
    $(link).up().insert({
       before: content.replace(regexp,new_id)
    });
}


